﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class DeleteActualGoodInStockHandler : ICommandHandler<DeleteActualGoodInStockCommand>
    {
        private readonly IActualGoodInStockRepository actualGoodInStockRepository;
        private readonly IUnitOfWork unitOfWork;
        public DeleteActualGoodInStockHandler(IActualGoodInStockRepository actualGoodInStockRepository, IUnitOfWork unitOfWork)
        {
            this.actualGoodInStockRepository = actualGoodInStockRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(DeleteActualGoodInStockCommand command)
        {
            var actualGoodInStock = actualGoodInStockRepository.GetById(command.ID);
            actualGoodInStockRepository.Delete(actualGoodInStock);
            unitOfWork.Commit();
            return new CommandResult(true);
        }


        public ICommandResult ExecuteRange(IEnumerable<DeleteActualGoodInStockCommand> commands)
        {
            var ids = commands.Select(y => y.ID);
            actualGoodInStockRepository.Delete(x => ids.Contains(x.ID));
            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult DeleteRange(IEnumerable<DeleteActualGoodInStockCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
